﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using E4D.AppFabric.Entities.Engine;
using System.Collections.ObjectModel;
using System.Management.Automation;

namespace UnitTests.Mocks
{
    class MockSession : ISession
    {
        private IList<Command> executedCommands;
        private IDictionary<String, Collection<PSObject>> response;

        public MockSession(IList<Command> executedCommands, IDictionary<String, Collection<PSObject>> response)
        {
            this.executedCommands = executedCommands;
            this.response = response;
        }

        public Collection<PSObject> Invoke(string commandName)
        {
            executedCommands.Add(new Command(commandName));

            Collection<PSObject> result;
            if (response.TryGetValue(commandName, out result))
                return result;
            else
                return new Collection<PSObject>();
        }

        public Collection<PSObject> Invoke(string commandName, IDictionary<string, object> parameters)
        {
            executedCommands.Add(new Command(commandName, parameters));
            Collection<PSObject> result;
            if (response.TryGetValue(commandName, out result))
                return result;
            else
                return new Collection<PSObject>();
        }

        public void Dispose()
        {

        }
    }
}
